<?php
/**
 * ListAction 
 * 
 * 获取产品列表，如果有关键字可实现关键字查询.
 * 如非必要，仅需配制配制文件
 */
class ListAction{
	
	public function action($_get){  
		require_once "Action/common.php";

		//获取分页信息

		$page_num = 1;
		if($_get['page']){
			if($_get['page']>100){
				$page_num = 93;
			}
			else{
				$page_num = $_get['page'];
			}
		}

		$cid = CID;													//默认CID
		if($_get['cid']){
			$cid = $_get['cid'];
			$cid = getNoiseCid($cid);
		}

		$keyword = '';												//查询关键字
		if($_get['keyword']){$keyword = urlencode($_get['keyword']);}


		//查询淘宝客推广商品(taobao.taobaoke.items.get)

		$Taoapi->method = 'taobao.taobaoke.items.get';

		$Taoapi->fields = 'num_iid,iid,title,nick,pic_url,price,click_url,commission,commission_rate,commission_num,commission_volume,seller_credit_score,item_location,shop_click_url';

		$Taoapi->nick = USERNICK;
		if($keyword){
			//设定关键字，须对汉字进行转换
			$Taoapi->keyword =  mb_convert_encoding(urldecode($keyword),"UTF-8","gb2312");
		}
		
		$Taoapi->cid = $cid;										//获取分类
		
		$Taoapi->page_no = $page_num;								//页码
		
		$Taoapi->page_size = PAGE_SIZE;								//分页大小

		
		$Taoapi->start_credit = STARTCREDIT;						//商家开始信用
		
		$Taoapi->end_credit = ENDCREDIT;							//商家结束信用
		
		$Taoapi->sort = SORTBY;										//推广商品排序

		//需要更多的字段可以登陆 taoapi.com 进行配置生成
		$TaobaokeData = $Taoapi->Send('get','xml')->getArrayData();
		
		//结果存入数组
		$show_array=array();
		$show_array= $TaobaokeData['taobaoke_items']['taobaoke_item'];
		

		$page_size		= PAGE_SIZE;								//每页显示数量
		$pageCurrent	= $page_num;								//当前页
		$sub_pages		= PAGE_ACTIVE;								//导航条中显示页面链接数
		//总数
		$nums			= ($TaobaokeData['total_results']>2000)?2000:$TaobaokeData['total_results'];	

		if($keyword==""){											//是否存在关键字
			$pageurl = SITEPATH."index.php/List/cid/".addNoise($d,$cid)."/page/";
		}
		else{
			$pageurl = SITEPATH."index.php/List/cid/".addNoise($d,$cid)."/keyword/". 
				mb_convert_encoding(urldecode($keyword),"UTF-8","gb2312")."/page/";
		}
		
		//分页
		$subPages = new SubPages($page_size,$nums,$pageCurrent,$sub_pages,$pageurl,2);
		$pages	  = $subPages->subPageCss2();



		//分配变量
		
		$list = getCateName($cid);									//获取分类列表

		$tpl->assign("nobaiduContent",$article);
		
		
		$tpl->assign("mm_index_key",KEYW.$list['listtitle']);		//关键字
		
		$tpl->assign("mm_index_des",DES.strip_tags($list['lists']).date("Y-m-d H:i:s"));			//描述
		
		$tpl->assign("mm_beian",ICPBEIAN);							//备案号
		
		$tpl->assign("mm_pages",$pages);							//分页
		
		$tpl->assign("item",$show_array);							//内容
		
		$tpl->assign("siteflag",FLAG);								//设定站点标记

		$tpl->assign("nobaidu",$nobaidu);							//不是百度?

		$tpl->assign("mm_listtitle",$list['listtitle']);			//列表标题
		
		$tpl->assign("mm_nav",$list['nav']);						//导航菜单
		
		$tpl->assign("mm_lists",$list['lists']);					//顶部分类
		
		$tpl->assign("mm_webname",SITETITLE);						//站点名称

		$tpl->display("mm_index.html","list");						//显示


		
	}
}
?>